package com.yanqu.road.server.cmd.rank;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/9/18 11:40
 */
@Cmd(code = GameProtocol.S_GET_PATRONS_RANK_DETAIL_INFO, desc = "查看门客榜门客详细信息")
public class GetPatronsRankDetailInfoCmd extends AbstractCommand {
    RankProto.GetPatronsRankDetailInfoReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = RankProto.GetPatronsRankDetailInfoReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (reqMsg.getServerId() == GameServer.getInstance().getServerId()) { //同服
            String patronsDetailInfoJsonStr = PatronsMgr.getUserPatronsDetailInfoJsonStr(reqMsg.getUserId(), reqMsg.getPatronsId());
            RankProto.GetPatronsRankDetailInfoRespMsg.Builder respMsg = RankProto.GetPatronsRankDetailInfoRespMsg.newBuilder();
            respMsg.setPatronsInfoJsonStr(patronsDetailInfoJsonStr);
            player.sendPacket(ClientProtocol.U_GET_PATRONS_RANK_DETAIL_INFO, respMsg);
        } else { //跨服
            YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_GET_PATRONS_RANK_DETAIL_INFO, reqMsg.toBuilder());
            GamePlayerMgr.sendPacket(player, message);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
